package com.alex.ioc.basic;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class SpringApplication {

    public static void main(String[] args) {
        // 创建 spring com.alex.ioc 容器对象
        ApplicationContext ctx = new ClassPathXmlApplicationContext("beans.xml");
        // 从 IOC 容器中获取 bean 实例
        Hello hello = (Hello) ctx.getBean("hello");
        Hello hello1 = ctx.getBean(Hello.class);
        // 调用bean方法
        hello.sayHello();

        Car car = (Car) ctx.getBean("car1");
        System.out.println(car);

        Person person1 = (Person) ctx.getBean("person1");
        person1.getCars().forEach(System.out::println);
        System.out.println();
        person1.getCarList().forEach(System.out::println);
        System.out.println();
        System.out.println(person1.getScores());
        System.out.println();
        System.out.println(person1.getInfo());
        System.out.println();
        System.out.println(person1);
        System.out.println();

        Person person5 = (Person) ctx.getBean("person5");
        System.out.println(person5);
        System.out.println();

        User user1 = (User) ctx.getBean("user1");
        System.out.println(user1);
    }
}
